import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 所有消息相关接口
 *
 * allen  2021-08-24
 */



/**
 * 获取报备未读消息数量
 */
const queryRecommendNotRead = () => {
  return new Promise((resolve, reject) => {
    get("/notify/recommend/get/notRead/number").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取系统未读消息数量
 */
const querySystemNotRead = () => {
  return new Promise((resolve, reject) => {
    get("/notify/system/get/notRead/number").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取楼盘未读消息数量
 */
const queryHouseNotRead = () => {
  return new Promise((resolve, reject) => {
    get("/notify/house/get/notRead/number").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 获取系统消息列表
 * @param {*} page 
 * @param {*} pageSize 
 */
const querySystemMsgList = (page, pageSize) => {
  return new Promise((resolve, reject) => {
    get("/notify/system?page=" + page + "&pageSize=" + pageSize).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 批量阅读系统消息 
 */
const batchReadSystemMsg = () => {
  return new Promise((resolve, reject) => {
    get("/notify/system/batch/read").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 读取单条系统消息
 * @param {*} id 
 */
const readSingleSystemMsg = (id) => {
  return new Promise((resolve, reject) => {
    get("/notify/system/read?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}




/**
 * 获取楼盘消息列表
 * @param {*} page 
 * @param {*} pageSize 
 */
const queryHouseMsgList = (page, pageSize) => {
  return new Promise((resolve, reject) => {
    get("/notify/house?page=" + page + "&pageSize=" + pageSize).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 批量阅读楼盘消息 
 */
const batchReadHouseMsg = () => {
  return new Promise((resolve, reject) => {
    get("/notify/house/batch/read").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 读取单条楼盘消息
 * @param {*} id 
 */
const readSingleHouseMsg = (id) => {
  return new Promise((resolve, reject) => {
    get("/notify/house/read?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 获取报备消息列表
 * @param {*} page 
 * @param {*} pageSize 
 */
const queryRecommendMsgList = (page, pageSize) => {
  return new Promise((resolve, reject) => {
    get("/notify/recommend?page=" + page + "&pageSize=" + pageSize).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 批量阅读报备消息 
 */
const batchReadRecommendMsg = () => {
  return new Promise((resolve, reject) => {
    get("/notify/recommend/batch/read").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}



/**
 * 读取单条报备消息
 * @param {*} id 
 */
const readSingleRecommendMsg = (id) => {
  return new Promise((resolve, reject) => {
    get("/notify/recommend/read?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

















module.exports = {
  queryRecommendNotRead,
  querySystemNotRead,
  queryHouseNotRead,
  querySystemMsgList,
  batchReadSystemMsg,
  readSingleSystemMsg,
  queryHouseMsgList,
  batchReadHouseMsg,
  readSingleHouseMsg,
  queryRecommendMsgList,
  batchReadRecommendMsg,
  readSingleRecommendMsg,
}
